package com.ruoyi.web.controller.zs;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ZsLeave;
import com.ruoyi.system.service.IZsLeaveService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 请假单Controller
 * 
 * @author jetlion
 * @date 2022-08-30
 */
@RestController
@RequestMapping("/system/leave")
public class ZsLeaveController extends BaseController
{
    @Autowired
    private IZsLeaveService zsLeaveService;

    /**
     * 查询请假单列表
     */
    @PreAuthorize("@ss.hasPermi('system:leave:list')")
    @GetMapping("/list")
    public TableDataInfo list(ZsLeave zsLeave)
    {
        startPage();
        List<ZsLeave> list = zsLeaveService.selectZsLeaveList(zsLeave);
        return getDataTable(list);
    }

    /**
     * 导出请假单列表
     */
    @PreAuthorize("@ss.hasPermi('system:leave:export')")
    @Log(title = "请假单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ZsLeave zsLeave)
    {
        List<ZsLeave> list = zsLeaveService.selectZsLeaveList(zsLeave);
        ExcelUtil<ZsLeave> util = new ExcelUtil<ZsLeave>(ZsLeave.class);
        util.exportExcel(response, list, "请假单数据");
    }

    /**
     * 获取请假单详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:leave:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(zsLeaveService.selectZsLeaveById(id));
    }

    /**
     * 新增请假单
     */
    @PreAuthorize("@ss.hasPermi('system:leave:add')")
    @Log(title = "请假单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZsLeave zsLeave)
    {
        return toAjax(zsLeaveService.insertZsLeave(zsLeave));
    }

    /**
     * 修改请假单
     */
    @PreAuthorize("@ss.hasPermi('system:leave:edit')")
    @Log(title = "请假单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZsLeave zsLeave)
    {
        return toAjax(zsLeaveService.updateZsLeave(zsLeave));
    }

    /**
     * 删除请假单
     */
    @PreAuthorize("@ss.hasPermi('system:leave:remove')")
    @Log(title = "请假单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(zsLeaveService.deleteZsLeaveByIds(ids));
    }
}
